const Response = require('../utils/response');
const reportService = require('../services/reportService');

class ReportController {
  // 获取举报列表
  async getReportList(req, res) {
    try {
      const reports = await reportService.getReportList();
      res.json(Response.success(reports));
    } catch (error) {
      res.json(Response.error(error.message));
    }
  }

  // 提交举报
  async submitReport(req, res) {
    try {
      const reportData = {
        ...req.body,
        reportUserId: req.user.id
      };
      const reportId = await reportService.submitReport(reportData);
      res.json(Response.success({ id: reportId }, '提交成功'));
    } catch (error) {
      res.json(Response.error(error.message));
    }
  }

  // 获取举报详情
  async getReportDetail(req, res) {
    try {
      const report = await reportService.getReportDetail(req.params.id);
      res.json(Response.success(report));
    } catch (error) {
      res.json(Response.error(error.message));
    }
  }

  // 处理举报
  async handleReport(req, res) {
    try {
      await reportService.handleReport(req.params.id, req.body);
      res.json(Response.success(null, '处理成功'));
    } catch (error) {
      res.json(Response.error(error.message));
    }
  }

  // 驳回举报
  async rejectReport(req, res) {
    try {
      await reportService.rejectReport(req.params.id, req.body.rejectReason);
      res.json(Response.success(null, '驳回成功'));
    } catch (error) {
      res.json(Response.error(error.message));
    }
  }

  // 删除举报
  async deleteReport(req, res) {
    try {
      await reportService.deleteReport(req.params.id);
      res.json(Response.success(null, '删除成功'));
    } catch (error) {
      res.json(Response.error(error.message));
    }
  }
}

module.exports = new ReportController(); 